# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2024/10/19
desc: 
sample: 
"""
import json

import jsonpath

# bookJson='{"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"J. R. R. Tolkien","title":"The Lord of the Rings","isbn":"0-395-19395-8","price":22.99}],' \
#     '"bicycle":{"color":"red","price":19.95}}}'

# f = open('json.csv','r')
# bookJson = f.read()
# f.close()
with open('json.csv','r') as f:
    bookJson = f.read()

books=json.loads(bookJson)
#路径 绝对路径
checkurl = "$.store.bicycle.price"
print(jsonpath.jsonpath(books, checkurl))
#获取所有价格 相对路径
checkurl = "$..price"
print(jsonpath.jsonpath(books, checkurl))
#数组
checkurl = "$.store.book[*]"
object_list=jsonpath.jsonpath(books, checkurl)
print(object_list)

checkurl = "$.store.book[0]"
object_list=jsonpath.jsonpath(books, checkurl)
print(object_list)